<template>
  <div class="analysis-card">
    <h3 class="analysis-title">短视频构成</h3>
    <div class="video-grid">
      <!-- 官号视频 -->
      <div class="video-section">
        <h4 class="section-subtitle">官号视频</h4>
        <div class="metrics-list">
          <div class="metric-item">
            <div class="metric-header">新发布视频</div>
            <div class="metric-content">
              <div class="main-value">{{ getData('官号视频-新发布视频') }}</div>
              <div class="data-comparison">
                <div class="rate-value" :class="getData('官号视频-新发布视频-较上周期变化').includes('+') ? 'rate-up' : 'rate-down'">
                  {{ getData('官号视频-新发布视频-较上周期变化') }}
                </div>
                <div class="previous-value">上期: {{ getPreviousValues('官号视频-新发布视频', '官号视频-新发布视频-较上周期变化')
                }}</div>
              </div>
            </div>
          </div>

          <div class="metric-item">
            <div class="metric-header">播放次数</div>
            <div class="metric-content">
              <div class="main-value">{{ getData('官号视频-播放次数') }}</div>
              <div class="data-comparison">
                <div class="rate-value" :class="getData('官号视频-播放次数-较上周期变化').includes('+') ? 'rate-up' : 'rate-down'">
                  {{ getData('官号视频-播放次数-较上周期变化') }}
                </div>
                <div class="previous-value">上期: {{ getPreviousValues('官号视频-播放次数', '官号视频-播放次数-较上周期变化') }}
                </div>
              </div>
            </div>
          </div>

          <div class="metric-item">
            <div class="metric-header">成交金额</div>
            <div class="metric-content">
              <div class="main-value">{{ getData('官号视频-成交金额') }}</div>
              <div class="data-comparison">
                <div class="rate-value" :class="getData('官号视频-成交金额-较上周期变化').includes('+') ? 'rate-up' : 'rate-down'">
                  {{ getData('官号视频-成交金额-较上周期变化') }}
                </div>
                <div class="previous-value">上期: {{ getPreviousValues('官号视频-成交金额', '官号视频-成交金额-较上周期变化') }}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 达人视频 -->
      <div class="video-section">
        <h4 class="section-subtitle">达人视频</h4>
        <div class="metrics-list">
          <div class="metric-item">
            <div class="metric-header">新发布视频</div>
            <div class="metric-content">
              <div class="main-value">{{ getData('达人视频-新发布视频') }}</div>
              <div class="data-comparison">
                <div class="rate-value" :class="getData('达人视频-新发布视频-较上周期变化').includes('+') ? 'rate-up' : 'rate-down'">
                  {{ getData('达人视频-新发布视频-较上周期变化') }}
                </div>
                <div class="previous-value">上期: {{ getPreviousValues('达人视频-新发布视频', '达人视频-新发布视频-较上周期变化')
                }}</div>
              </div>
            </div>
          </div>

          <div class="metric-item">
            <div class="metric-header">播放次数</div>
            <div class="metric-content">
              <div class="main-value">{{ getData('达人视频-播放次数') }}</div>
              <div class="data-comparison">
                <div class="rate-value" :class="getData('达人视频-播放次数-较上周期变化').includes('+') ? 'rate-up' : 'rate-down'">
                  {{ getData('达人视频-播放次数-较上周期变化') }}
                </div>
                <div class="previous-value">上期: {{ getPreviousValues('达人视频-播放次数', '达人视频-播放次数-较上周期变化') }}
                </div>
              </div>
            </div>
          </div>

          <div class="metric-item">
            <div class="metric-header">成交金额</div>
            <div class="metric-content">
              <div class="main-value">{{ getData('达人视频-成交金额') }}</div>
              <div class="data-comparison">
                <div class="rate-value" :class="getData('达人视频-成交金额-较上周期变化').includes('+') ? 'rate-up' : 'rate-down'">
                  {{ getData('达人视频-成交金额-较上周期变化') }}
                </div>
                <div class="previous-value">上期: {{ getPreviousValues('达人视频-成交金额', '达人视频-成交金额-较上周期变化') }}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 店员视频 -->
      <div class="video-section">
        <h4 class="section-subtitle">店员视频</h4>
        <div class="metrics-list">
          <div class="metric-item">
            <div class="metric-header">新发布视频</div>
            <div class="metric-content">
              <div class="main-value">{{ getData('店员视频-新发布视频') }}</div>
              <div class="data-comparison">
                <div class="rate-value" :class="getData('店员视频-新发布视频-较上周期变化').includes('+') ? 'rate-up' : 'rate-down'">
                  {{ getData('店员视频-新发布视频-较上周期变化') }}
                </div>
                <div class="previous-value">上期: {{ getPreviousValues('店员视频-新发布视频', '店员视频-新发布视频-较上周期变化')
                }}</div>
              </div>
            </div>
          </div>

          <div class="metric-item">
            <div class="metric-header">播放次数</div>
            <div class="metric-content">
              <div class="main-value">{{ getData('店员视频-播放次数') }}</div>
              <div class="data-comparison">
                <div class="rate-value" :class="getData('店员视频-播放次数-较上周期变化').includes('+') ? 'rate-up' : 'rate-down'">
                  {{ getData('店员视频-播放次数-较上周期变化') }}
                </div>
                <div class="previous-value">上期: {{ getPreviousValues('店员视频-播放次数', '店员视频-播放次数-较上周期变化') }}
                </div>
              </div>
            </div>
          </div>

          <div class="metric-item">
            <div class="metric-header">成交金额</div>
            <div class="metric-content">
              <div class="main-value">{{ getData('店员视频-成交金额') }}</div>
              <div class="data-comparison">
                <div class="rate-value" :class="getData('店员视频-成交金额-较上周期变化').includes('+') ? 'rate-up' : 'rate-down'">
                  {{ getData('店员视频-成交金额-较上周期变化') }}
                </div>
                <div class="previous-value">上期: {{ getPreviousValues('店员视频-成交金额', '店员视频-成交金额-较上周期变化') }}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- UGC视频 -->
      <div class="video-section">
        <h4 class="section-subtitle">UGC视频</h4>
        <div class="metrics-list">
          <div class="metric-item">
            <div class="metric-header">新发布视频</div>
            <div class="metric-content">
              <div class="main-value">{{ getData('UGC视频-新发布视频') }}</div>
              <div class="data-comparison">
                <div class="rate-value" :class="getData('UGC视频-新发布视频-较上周期变化').includes('+') ? 'rate-up' : 'rate-down'">
                  {{ getData('UGC视频-新发布视频-较上周期变化') }}
                </div>
                <div class="previous-value">上期: {{ getPreviousValues('UGC视频-新发布视频', 'UGC视频-新发布视频-较上周期变化') }}</div>
              </div>
            </div>
          </div>

          <div class="metric-item">
            <div class="metric-header">播放次数</div>
            <div class="metric-content">
              <div class="main-value">{{ getData('UGC视频-播放次数') }}</div>
              <div class="data-comparison">
                <div class="rate-value" :class="getData('UGC视频-播放次数-较上周期变化').includes('+') ? 'rate-up' : 'rate-down'">
                  {{ getData('UGC视频-播放次数-较上周期变化') }}
                </div>
                <div class="previous-value">上期: {{ getPreviousValues('UGC视频-播放次数', 'UGC视频-播放次数-较上周期变化') }}</div>
              </div>
            </div>
          </div>

          <div class="metric-item">
            <div class="metric-header">成交金额</div>
            <div class="metric-content">
              <div class="main-value">{{ getData('UGC视频-成交金额') }}</div>
              <div class="data-comparison">
                <div class="rate-value" :class="getData('UGC视频-成交金额-较上周期变化').includes('+') ? 'rate-up' : 'rate-down'">
                  {{ getData('UGC视频-成交金额-较上周期变化') }}
                </div>
                <div class="previous-value">上期: {{ getPreviousValues('UGC视频-成交金额', 'UGC视频-成交金额-较上周期变化') }}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { getPreviousValue } from '../../../utils'
interface ReportItem {
  name: string
  value: string
}

interface ReportSection {
  title: string
  items: ReportItem[]
}

interface Props {
  sectionData: ReportSection
}
const getPreviousValues = (currentKey: string, changeKey: string,): string => {
console.log("🚀 ~ getPreviousValues ~ currentKey:", currentKey)

const currentValue = getData(currentKey)
const changeValue = getData(changeKey)
return getPreviousValue(currentValue, changeValue)
}
const props = defineProps<Props>()

const getData = (key: string): string => {
  const item = props.sectionData.items.find(item => item.name === key)
  return item?.value ?? '-'
}


</script>

<style scoped>
.analysis-card {
  margin-bottom: 20px;
  padding: 15px 20px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.analysis-title {
  font-size: 18px;
  color: #2d3748;
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 2px solid #e2e8f0;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.video-section {
  background: #f8fafc;
  border-radius: 8px;
  padding: 15px;
}

.section-subtitle {
  font-size: 14px;
  color: #1a365d;
  margin-bottom: 12px;
  padding-left: 8px;
  border-left: 3px solid #4a5568;
}

.metrics-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.metric-item {
  background: #ffffff;
  border-radius: 8px;
  padding: 12px 15px;
}

.metric-header {
  color: #4a5568;
  font-size: 13px;
  margin-bottom: 6px;
}

.metric-content {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  justify-content: space-between;
}

.main-value {
  font-size: 24px;
  font-weight: 600;
  color: #2d3748;
  line-height: 1;
}

.data-comparison {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.rate-value {
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1.2;
}

.previous-value {
  font-size: 11px;
  color: #718096;
  margin-top: 2px;
}

.rate-up {
  color: #22c55e;
  background: rgba(34, 197, 94, 0.1);
}

.rate-down {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

@media (max-width: 768px) {
  .video-grid {
    grid-template-columns: 1fr;
  }
}
</style>